package com.satan.fmmall.config;

import com.satan.fmmall.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WebMvcConfig
 * @Description TODO
 * @date 2022/2/19 20:25
 * @Version 1.0
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private LoginInterceptor loginInterceptor;
    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE","PATCH")
                .allowedHeaders("*")
                .maxAge(3600);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePathList = new ArrayList<>();
        excludePathList.add("/user/*");
        excludePathList.add("/index/*");
        excludePathList.add("/detail/*");
//        excludePathList.add("/shopcart/list");
//        excludePathList.add("/shopcart/update/**");
//        excludePathList.add("/shopcart/delete/**");
//        excludePathList.add("/order/**");
//        excludePathList.add("/pay/**");
        registry.addInterceptor(loginInterceptor).excludePathPatterns(excludePathList).addPathPatterns("/shopcart/*");
    }

}
